/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2013
 */

package org.teacup.eightdays.model;

import javax.persistence.*;

import org.hibernate.annotations.GenericGenerator;

import javax.validation.constraints.*;
import org.hibernate.validator.constraints.*;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import org.teacup.eightdays.model.*;
import org.teacup.eightdays.dao.*;
import org.teacup.eightdays.service.*;
import org.teacup.eightdays.vo.query.*;

/**
 * @author Abner email:521yexu2008(a)163.com
 * @version 1.0
 * @since 1.0
 */

@Entity
@Table(name = "product_type")
public class ProductType extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "ProductType";
	public static final String ALIAS_PRODUCT_TYPE_ID = "ID";
	public static final String ALIAS_NAME = "类型名称";
	public static final String ALIAS_PARENT_ID = "父类型ID";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
    /**
     * ID       db_column: product_type_id 
     */ 	
	
	private java.lang.Long productTypeId;
    /**
     * 类型名称       db_column: name 
     */ 	
	@NotBlank @Length(max=100)
	private java.lang.String name;
    /**
     * 父类型ID       db_column: parent_id 
     */ 	
	@NotNull 
	private java.lang.Long parentId;
	//columns END


	public ProductType(){
	}

	public ProductType(
		java.lang.Long productTypeId
	){
		this.productTypeId = productTypeId;
	}

	

	public void setProductTypeId(java.lang.Long value) {
		this.productTypeId = value;
	}
	
	@Id @GeneratedValue(generator="custom-id")
	@GenericGenerator(name="custom-id", strategy = "increment")
	@Column(name = "product_type_id", unique = true, nullable = false, insertable = true, updatable = true, length = 19)
	public java.lang.Long getProductTypeId() {
		return this.productTypeId;
	}
	
	@Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
	public java.lang.String getName() {
		return this.name;
	}
	
	public void setName(java.lang.String value) {
		this.name = value;
	}
	
	@Column(name = "parent_id", unique = false, nullable = false, insertable = true, updatable = true, length = 19)
	public java.lang.Long getParentId() {
		return this.parentId;
	}
	
	public void setParentId(java.lang.Long value) {
		this.parentId = value;
	}
	
	
	private Set products = new HashSet(0);
	public void setProducts(Set<Product> product){
		this.products = product;
	}
	
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "productType")
	public Set<Product> getProducts() {
		return products;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("ProductTypeId",getProductTypeId())
			.append("Name",getName())
			.append("ParentId",getParentId())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getProductTypeId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof ProductType == false) return false;
		if(this == obj) return true;
		ProductType other = (ProductType)obj;
		return new EqualsBuilder()
			.append(getProductTypeId(),other.getProductTypeId())
			.isEquals();
	}
}

